<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>邀请新用户</title>
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="fonts/glyphicons-halflings-regular.woff2">
</head>
<body>
<div id="top"></div>
<div style="margin-top: 10%;margin-left: 5%">
    <div class="form-group">
        <button type="button" id="getInviteCode" class="btn-warning" >生成邀请码</button>
        <input id="inviteCode" type="text" class="form-control">
    </div>
    <button id="confirm" class="btn btn-warning">确定</button>
</div>

<script type="text/javascript" src="js/jquery-3.6.4.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#top").load("top.html")
        //获取页面传来的参数
        const searchParams = new URLSearchParams(location.search);
        // 获取商品id
        const pId = searchParams.get("pId");
        //获取优惠金额
        const refundCount = searchParams.get("refundCount")/2;
        //邀请码
        let inviteCode;
        $("#getInviteCode").click(function (){
            //生成邀请码
            $.ajax({
                url:"/PDD/product?method=getInviteCode",
                success:function (data){
                    inviteCode=data
                    $("#inviteCode").val(inviteCode).prop('readOnly', true);
                }
            })
        })
        //确定点击事件
        $("#confirm").click(function (){
            //后台插入邀请码数据
            $.ajax({
                url:"/PDD/product?method=addInviteDetail",
                data:{
                    "pId":pId,
                    "refundCount":refundCount,
                    "inviteCode":inviteCode
                },
                dataType:"json",
                success:function (){
                    window.history.back()
                }
            })
        })
    })
</script>
</body>
</html>